
package com.xebest.web.controller.order;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.xebest.api.dto.OperatorLogRequestDTO;
import com.xebest.api.dto.OperatorLogResponseDTO;
import com.xebest.api.service.OperatorService;
import com.xebest.common.base.controller.BASEMessage;
import com.xebest.common.base.controller.BaseController;
import com.xebest.common.base.controller.BaseResponse;
import com.xebest.common.enums.cms.SysCmsPagePlatEnum;
import com.xebest.common.enums.erp.order.*;
import com.xebest.common.enums.erp.storehouse.VenStoreTypeEnum;
import com.xebest.common.enums.logtype.ErpLogTypeEnum;
import com.xebest.common.enums.util.EnumUtil;
import com.xebest.config.ParamConfig;
import com.xebest.constant.XeConstans;
import com.xebest.util.DateUtil;
import com.xebest.util.SysSetBeanUtils;
import com.xebest.util.XeVenBusConstans;
import com.xebest.util.msg.XeVenOrderMsg;
import com.xebest.web.form.XeVenOrderForm;
import com.xebest.web.form.XeVenOrderFromVo;
import com.xebest.web.form.XeVenOrderLogisticsForm;
import com.xebest.web.form.XeVenSplitOrderForm;
import com.xebest.web.model.XeVenOrderInfoDetailEntity;
import com.xebest.web.model.XeVenOrderLogisticsDetail;
import com.xebest.web.model.base.XePageInfo;
import com.xebest.web.service.XeVenOrderLogisticsService;
import com.xebest.web.service.XeVenOrderService;
import com.xebest.web.view.ErpUserInfo;
import com.xebest.web.view.XeVenOrderView;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单处理
 *
 * @author ruancz
 */
@RestController
@RequestMapping("order")
public class XeVenOrderController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(XeVenOrderController.class);//日志记录类

    /**
     * 订单操作service
     */
    @Autowired
    private XeVenOrderService xeVenOrderService;
    @Autowired
    private OperatorService operatorService;

    @Autowired
    private ParamConfig paramConfig;//获取公共配置信息
    @Autowired
    private XeVenOrderLogisticsService xeVenOrderLogisticsService;//获取物流信息

    /**
     * 查询代付款订单列表
     *
     * @author ruancz
     */
    @RequestMapping("queryPendingPaymentOrder")
    public @ResponseBody
    BaseResponse queryPendingPaymentOrderList(@RequestBody XeVenOrderForm form) {

        log.info("查询代付款订单列表 请求参数为：{}", JSON.toJSONString(form));
        form.setPayStatus(VenOrderPayStatusEnum.UNPAID.getValue());
        form.setPayType(VenOrderPayTypeEnum.ONLINE_PAY.getValue());
        form.setZpOrder(XeConstans._XE_ONE);
        form.setOrderStatus(VenOrderStatusEnum.WAIT_DIS.getValue());
        form.setOrderException(VenOrderExpFlagEnum.NO_PROBLEM.getValue());
        if (judgeOrderTime(form)) return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.TIME_MSG);
        setOrderTime(form);
        XePageInfo<XeVenOrderView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        //设置时间
        //查询列表
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            List<XeVenOrderView> orderInfoList = this.xeVenOrderService.queryOrderInfoList(form, userInfo);
            xePageInfo = new XePageInfo<XeVenOrderView>(orderInfoList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("actionList", orderInfoList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询代付款订单列表：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询订单列表接口
     *
     * @author ruancz
     */
    @RequestMapping("queryOrderList")
    public @ResponseBody
    BaseResponse queryOrderList(@RequestBody XeVenOrderForm form) {

        log.info("查询订单列表接口  请求参数为：{}", JSON.toJSONString(form));

        if (null == form.getOrderStatus()) {
            if (StringUtils.isBlank(form.getOrderId())) {
                form.setNoOrderStatus(VenOrderStatusEnum.CANCEL.getValue());
            }
        }
        if (judgeOrderTime(form)) return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.TIME_MSG);
        //设置时间
        setOrderTime(form);
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            XePageInfo<XeVenOrderView> xePageInfo;
            PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
            List<XeVenOrderView> orderInfoList = this.xeVenOrderService.queryOrderInfoList(form, userInfo);
            xePageInfo = new XePageInfo<XeVenOrderView>(orderInfoList);
            map.put("actionList", orderInfoList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询订单列表接口异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询订单列表统计接口
     *
     * @author ruancz
     */
    @RequestMapping("queryCountOrderInfo")
    public @ResponseBody
    BaseResponse queryCountOrderInfo(@RequestBody XeVenOrderForm form) {
        log.info("查询订单列表接口  请求参数为：{}", JSON.toJSONString(form));

        if (null == form.getOrderStatus()) {
            if (StringUtils.isBlank(form.getOrderId())) {
                form.setNoOrderStatus(VenOrderStatusEnum.CANCEL.getValue());
            }
        }
        if (judgeOrderTime(form)) return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.TIME_MSG);
        setOrderTime(form);
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            //统计数量
            Long countDeliveryOrder = 0L;  //货到付款订单数
            Long countOnLineOrder = 0L;    //在线支付订单数
            BigDecimal countDeliveryOrderPrice = new BigDecimal("0"); //货到付款总格
            BigDecimal countOnLineOrderPrice = new BigDecimal("0");  //在线支付总价
            BigDecimal averageUnitPrice = new BigDecimal("0");  //客单价
            List<Map<String, Object>> list = this.xeVenOrderService.queryCountOrderInfo(form, userInfo);
            if (null != list && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    Map<String, Object> resMap = list.get(i);
                    if (resMap.containsKey("payType")) {
                        //货到付款
                        if (resMap.get("payType").toString().equals(XeConstans._XE_STR_ONE)) {
                            countDeliveryOrder = Long.parseLong(resMap.get("countOrder").toString());
                            countDeliveryOrderPrice = countDeliveryOrderPrice.add(new BigDecimal(resMap.get("sumPrice").toString()));
                        } else { //在线支付
                            countOnLineOrder = Long.parseLong(resMap.get("countOrder").toString());
                            countOnLineOrderPrice = countOnLineOrderPrice.add(new BigDecimal(resMap.get("sumPrice").toString()));
                        }
                    }
                }
            }
            if ((countOnLineOrder + countDeliveryOrder) != 0) {
                averageUnitPrice = averageUnitPrice.add(countDeliveryOrderPrice.add(countOnLineOrderPrice).divide(new BigDecimal(countDeliveryOrder + countOnLineOrder), 2, BigDecimal.ROUND_UP));
            }
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("countOrder", countDeliveryOrder + countOnLineOrder);
            map.put("countDeliveryOrder", countDeliveryOrder);
            map.put("countOnLineOrder", countOnLineOrder);
            map.put("countOrderPrice", countDeliveryOrderPrice.add(countOnLineOrderPrice).divide(new BigDecimal("10000")).setScale(2, RoundingMode.HALF_UP));
            map.put("countDeliveryOrderPrice", countDeliveryOrderPrice.divide(new BigDecimal("10000")).setScale(2, RoundingMode.HALF_UP));
            map.put("countOnLineOrderPrice", countOnLineOrderPrice.divide(new BigDecimal("10000")).setScale(2, RoundingMode.HALF_UP));
            map.put("averageUnitPrice", averageUnitPrice);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询订单列表统计接口异常：{}", e);
            return sendAjaxError();
        }
    }

    private boolean judgeOrderTime(@RequestBody XeVenOrderForm form) {
        if (StringUtils.isBlank(form.getEndCreateDate()) && StringUtils.isBlank(form.getStartCreateDate())) {
            form.setEndCreateDate(DateUtil.getDate(new Date()));
        }
        if (StringUtils.isBlank(form.getStartCreateDate()) && StringUtils.isNotBlank(form.getEndCreateDate())) {
            String time = DateUtil.strToNMonth(form.getEndCreateDate(), -3);
            form.setStartCreateDate(time);
        }
        if (StringUtils.isBlank(form.getEndCreateDate()) && StringUtils.isNotBlank(form.getStartCreateDate())) {
            String time = DateUtil.strToNMonth(form.getStartCreateDate(), 3);
            form.setEndCreateDate(time);
        }
        if (StringUtils.isNotBlank(form.getStartCreateDate()) && StringUtils.isNotBlank(form.getEndCreateDate())) {
            boolean flag = DateUtil.comparableTime(form.getStartCreateDate(), form.getEndCreateDate());
            if (!flag) {
                return true;
            }
        }
        return false;
    }

    private void setOrderTime(XeVenOrderForm form) {
        if (null != form.getSearchType()) {
            switch (form.getSearchType()) {
                case 1:
                    break;
                case 2:
                    form.setPayNumber(form.getOrderId());
                    form.setOrderId(null);
                    break;
                case 3:
                    form.setProName(form.getOrderId());
                    form.setOrderId(null);
                    break;
                case 4:
                    form.setProNum(form.getOrderId());
                    form.setOrderId(null);
                    break;
                case 5:
                    form.setCaConsignee(form.getOrderId());
                    form.setOrderId(null);
                    break;
                case 6:
                    form.setLoginAccount(form.getOrderId());
                    form.setOrderId(null);
                    break;
                case 7:
                    form.setCheckBatchNum(form.getOrderId());
                    form.setOrderId(null);
                    break;
                case 8:
                    form.setPrintBatchNum(form.getOrderId());
                    form.setOrderId(null);
                    break;
                default:
                    break;
            }
        }
        if (null != form.getSearchTimeType()) {
            switch (form.getSearchTimeType()) {
                case 1:
                    break;
                case 2:
                    form.setStartPayTime(form.getStartCreateDate());
                    form.setEndPayTime(form.getEndCreateDate());
                    form.setStartCreateDate(null);
                    form.setEndCreateDate(null);
                    break;
                case 3:
                    form.setStartSendTime(form.getStartCreateDate());
                    form.setEndSendTime(form.getEndCreateDate());
                    form.setStartCreateDate(null);
                    form.setEndCreateDate(null);
                    break;
                default:
                    break;
            }
        }
    }

    /**
     * 查询异常订单列表
     *
     * @author ruancz
     */
    @RequestMapping("queryExceptionOrder")
    public @ResponseBody
    BaseResponse queryExceptionOrderList(@RequestBody XeVenOrderForm form) {

        log.info("查询异常订单列表 请求参数为：{}", JSON.toJSONString(form));
        form.setOrderException(VenOrderExpFlagEnum.PROBLEM.getValue());
        form.setZpOrder(XeConstans._XE_ONE);
        //设置时间
        if (judgeOrderTime(form)) return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.TIME_MSG);
        setOrderTime(form);
        XePageInfo<XeVenOrderView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        //查询列表
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            List<XeVenOrderView> orderInfoList = this.xeVenOrderService.queryOrderInfoList(form, userInfo);
            xePageInfo = new XePageInfo<XeVenOrderView>(orderInfoList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("actionList", orderInfoList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询异常订单列表：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 订单处理列表
     *
     * @author: ruancz
     */
    @RequestMapping("queryHandleOrderList")
    public @ResponseBody
    BaseResponse queryHandleOrderList(@RequestBody XeVenOrderForm form) {

        log.info("查询订单处理列表请求参数为： {}", JSON.toJSONString(form));
        //设置时间
        if (judgeOrderTime(form)) return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.TIME_MSG);
        setOrderTime(form);
        form.setOrderStatus(VenOrderStatusEnum.WAIT_CHECK.getValue());
        form.setZpOrder(XeConstans._XE_ONE);
        form.setOrderException(VenOrderExpFlagEnum.NO_PROBLEM.getValue());
        XePageInfo<XeVenOrderView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            //返回结果
            List<XeVenOrderView> orderInfoList = this.xeVenOrderService.queryOrderInfoList(form, userInfo);
            xePageInfo = new XePageInfo<XeVenOrderView>(orderInfoList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("actionList", orderInfoList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询订单处理列表异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询订单打印发货列表
     *
     * @author ruancz
     */
    @RequestMapping("querySendOrder")
    public @ResponseBody
    BaseResponse querySendOrderList(@RequestBody XeVenOrderForm form) {

        log.info("查询订单打印发货列表：{}", JSON.toJSONString(form));
        //设置时间
        if (judgeOrderTime(form)) return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.TIME_MSG);
        setOrderTime(form);
        if (null == form.getOrderStatus()) {
            form.setOrderStatu(new String[]{"1", "2", "3"});
        }
        form.setZpOrder(XeConstans._XE_ONE);
        form.setOrderException(VenOrderExpFlagEnum.NO_PROBLEM.getValue());
        form.setAllStoreType("allStoreType");
        XePageInfo<XeVenOrderView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        //查询列表
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            List<XeVenOrderView> orderInfoList = this.xeVenOrderService.queryOrderInfoList(form, userInfo);
            xePageInfo = new XePageInfo<XeVenOrderView>(orderInfoList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("actionList", orderInfoList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询订单打印发货列表：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询汇总采购列表
     *
     * @author ruancz
     */
    @RequestMapping("querySummaryPurch")
    public @ResponseBody
    BaseResponse querySummaryPurchOrder(@RequestBody XeVenOrderForm form) {
        log.info("查询汇总采购列表  请求参数为：{}", JSON.toJSONString(form));

        if (judgeOrderTime(form)) return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.TIME_MSG);
        setOrderTime(form);
        //必须查询分拨仓库的订单
        form.setStoreType(VenStoreTypeEnum.ALLOCATE_STORE.getValue());
        form.setZpOrder(XeConstans._XE_ONE);
        form.setOrderException(VenOrderExpFlagEnum.NO_PROBLEM.getValue());
        XePageInfo<XeVenOrderView> xePageInfo;
        PageHelper.startPage(form.getPageNum(), form.getPageSize(), true);
        //查询列表
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        Map<String, Object> map = new HashMap<String, Object>();
        //设置时间
        try {
            List<XeVenOrderView> orderInfoList = this.xeVenOrderService.queryOrderInfoList(form, userInfo);
            xePageInfo = new XePageInfo<XeVenOrderView>(orderInfoList);
            map.put("actionList", orderInfoList);
            map.put("xePageInfo", xePageInfo);
            return sendAjaxOK(map);
        } catch (Exception e) {
            log.error("查询汇总采购列表：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询订单明细接口
     *
     * @author ruancz
     */
    @RequestMapping("queryOrderInfoDetail")
    public @ResponseBody
    BaseResponse queryOrderInfoDetail(@RequestBody XeVenOrderForm form) {

        log.info("查询订单明细接口请求参数为：{}", JSON.toJSONString(form));
        //验证必要参数
        if (StringUtils.isBlank(form.getOrderId())) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            //返回结果
            Map<String, Object> resultMap = this.xeVenOrderService.queryOrderInfoDetail(form.getOrderId(), userInfo);
            resultMap.put("picServer", paramConfig.getImgUrl() + XeConstans.ERP_PRO_PIC_DIR); //图片服务器地址
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询订单明细接口异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询订单日志
     *
     * @author ruancz
     */
    @RequestMapping("queryOrderInfoLog")
    public @ResponseBody
    BaseResponse queryOrderInfoLog(@RequestBody OperatorLogRequestDTO dto) {
        log.info("查询订单日志信息：{}", JSON.toJSONString(dto));
        try {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            dto.setUserCode(userInfo.getUserCode());
            log.info("查询订单日志入参信息：{}", JSON.toJSONString(dto));
            OperatorLogResponseDTO operatorLogResponseDTO = this.operatorService.queryOperatorLog(dto);
            //log.info("查询订单日志信息返回信息：{}",JSON.toJSONString(operatorLogResponseDTO));
            if (null != operatorLogResponseDTO.getOperatorLogList() && operatorLogResponseDTO.getOperatorLogList().size() > 0) {
                for (int i = 0; i < operatorLogResponseDTO.getOperatorLogList().size(); i++) {
                    String name = EnumUtil.getEnumNameByValue(ErpLogTypeEnum.class, operatorLogResponseDTO.getOperatorLogList().get(i).getLogType());
                    operatorLogResponseDTO.getOperatorLogList().get(i).setLogType(name);
                }
            }
            resultMap.put("logisticsList", operatorLogResponseDTO.getOperatorLogList());
            resultMap.put("pageInfo", operatorLogResponseDTO.getPageInfo());
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询订单日志信息：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询订单物流信息
     *
     * @author ruancz
     */
    @RequestMapping("queryOrderLogistics")
    public @ResponseBody
    BaseResponse queryOrderLogistics(@RequestBody XeVenOrderLogisticsForm orderLogisticsForm) {
        log.info("查询订单物流信息：{}", JSON.toJSONString(orderLogisticsForm));
        if (null == orderLogisticsForm && StringUtils.isBlank(orderLogisticsForm.getOrderId())) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        Map<String, Object> resultMap = new HashMap<String, Object>();
        try {
            orderLogisticsForm.setUserCode(userInfo.getUserCode());
            List<XeVenOrderLogisticsDetail> orderLogisticsDetailList = this.xeVenOrderLogisticsService.selectLogisticsDetailList(orderLogisticsForm);
            resultMap.put("logisticsList", orderLogisticsDetailList);
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询订单物流信息：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 修改订单 统一接口（修改运费,备注,收货人信息）
     *
     * @author ruancz
     */
    @RequestMapping("updateOrderInfo")
    public @ResponseBody
    BaseResponse updateOrderInfo(@RequestBody XeVenOrderForm forms) {

        log.info("修改订单请求参数为：{}", JSON.toJSONString(forms));
        //判断订单是否锁单
        if (forms.getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
            return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            //返回结果
            int flag = this.xeVenOrderService.updateOrderInfo(forms, userInfo);
            //添加日志
            String operContent = "修改订单【" + forms.getOrderId() + "】的订单信息，修改内容：收货人姓名改为" + forms.getCaConsignee() + "，收货人手机改为" + forms.getCaPhone() + "，收货店铺改为" + forms.getStoreName()
                    + "，客户经理改为" + forms.getSalesmanName() + "，收货地址改为" + forms.getCaProvinceId() + forms.getCaCityId() + forms.getCaAreaId() + "，详细地址改为" + forms.getCaStreet() + ",订单备注为" + forms.getOrderRemark() + "。";
            xeVenOrderService.insertMqLog(ErpLogTypeEnum.erpOrderModify.getValue(), forms.getOrderId(), operContent + (flag == 1 ? "修改订单成功" : "修改订单失败"), userInfo, getRequestIP(), null);

            if (flag == XeConstans._XE_ONE) {
                return sendAjaxOK();
            } else {
                return sendAjaxError();
            }
        } catch (Exception e) {
            log.error("修改订单异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 异常订单列表更新订单 (重新分仓)
     *
     * @author ruancz
     */
    @RequestMapping("updateExceptionOrder")
    public @ResponseBody
    BaseResponse updateExceptionOrder(@RequestBody XeVenOrderFromVo formList) {

        log.info("更新异常订单请求参数为：{}", JSON.toJSONString(formList));
        //验证请求参数
        boolean flag = ((null == formList) || formList.getXeVenOrderForm().size() == XeConstans._XE_ZERO || formList.getXeVenOrderForm().size() > XeConstans._XE_TEN);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.updateExceptionOrder(formList.getXeVenOrderForm(), userInfo);
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("更新异常订单异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 批量修改仓库
     *
     * @author ruancz
     */
    @RequestMapping("updateOrderStore")
    public @ResponseBody
    BaseResponse updateOrderStore(@RequestBody XeVenOrderFromVo formList) {
        log.info("修改仓库请求参数为：{}", JSON.toJSONString(formList));
        //验证必要参数
        boolean flag = ((null == formList) || formList.getXeVenOrderForm().size() == XeConstans._XE_ZERO || formList.getXeVenOrderForm().size() > XeConstans._XE_TEN);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        for (int i = 0; i < formList.getXeVenOrderForm().size(); i++) {
            //判断订单是否锁单
            if (formList.getXeVenOrderForm().get(i).getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
            }
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            Map<String, Object> resulMap = this.xeVenOrderService.updateOrderStore(formList.getXeVenOrderForm(), userInfo, getRequestIP());
            return this.sendAjaxOK(resulMap);
        } catch (Exception e) {
            log.error("订单修改仓库：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 更新运费金额
     *
     * @author ruancz
     */
    @RequestMapping("updateFreAmount")
    public @ResponseBody
    BaseResponse updateFreAmount(@RequestBody XeVenOrderForm xeVenOrderForm) {
        log.info("更新运费金额请求参数为：{}", JSON.toJSONString(xeVenOrderForm));
        //验证必要参数
        boolean flag = StringUtils.isBlank(xeVenOrderForm.getOrderId()) &&
                StringUtils.isBlank(xeVenOrderForm.getFreAmount().toString());
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        //判断订单是否锁单
        if (xeVenOrderForm.getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
            return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
        }
        //在线支付未付款和货到付款订单可以修改运费金额
        boolean dataError = (VenOrderPayTypeEnum.ARRIVE_PAY.getValue() == xeVenOrderForm.getPayType())
                || (VenOrderPayStatusEnum.UNPAID.getValue() == xeVenOrderForm.getPayStatus()
                && VenOrderPayTypeEnum.ONLINE_PAY.getValue() == xeVenOrderForm.getPayType());
        if (!dataError) {
            return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.NOPAY_ORDER);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            int result = this.xeVenOrderService.updateFreAmount(xeVenOrderForm, userInfo, getRequestIP());
            Map<String, Object> resultMap = new HashMap<String, Object>();
            if (result == XeConstans._XE_ONE) {
                resultMap.put(XeVenBusConstans.CODE, XeVenBusConstans.BUSSINESS_SUCCESS);
                resultMap.put(XeVenBusConstans.MSG, XeVenOrderMsg.SUCCESS);
            } else {
                resultMap.put(XeVenBusConstans.CODE, XeVenBusConstans.BUSSINESS_ERROR);
                resultMap.put(XeVenBusConstans.MSG, XeVenOrderMsg.FRE_AMOUNT_FAIL);
            }
            return this.sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("更新运费金额异常：{}", e);
            return sendAjaxError();
        }
    }


    /**
     * 更新特批优惠金额
     *
     * @author ruancz
     */
    @RequestMapping("updateSpecialDisamount")
    public @ResponseBody
    BaseResponse updateSpecialDisamount(@RequestBody XeVenOrderFromVo xeVenOrderForm) {

        log.info("更新特批优惠金额请求参数为：{}", JSON.toJSONString(xeVenOrderForm));
        //验证必要参数
        boolean flag = (null == xeVenOrderForm) || (xeVenOrderForm.getXeVenOrderForm().size() == XeConstans._XE_ZERO);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());

        for (int i = 0; i < xeVenOrderForm.getXeVenOrderForm().size(); i++) {
            //判断订单是否锁单
            if (xeVenOrderForm.getXeVenOrderForm().get(i).getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
            }
            XeVenOrderForm tempOrder = xeVenOrderForm.getXeVenOrderForm().get(i);
            //验证数据是否合法
            Map<String, Object> detailParam = new HashMap<String, Object>();
            detailParam.put("orderId", tempOrder.getOrderId());
            detailParam.put("userCode", userInfo.getUserCode());
            detailParam.put("itemId", tempOrder.getItemId());
            detailParam.put("proSku", tempOrder.getProSku());
            List<XeVenOrderInfoDetailEntity> detailEntities = xeVenOrderService.getWriteOrderDetailByParam(detailParam);
            if (null != detailEntities && detailEntities.size() > 0) {
                XeVenOrderInfoDetailEntity detail = detailEntities.get(0);
                log.info("更新运费金额请求参数为,验证前端特批旧金额是否传递参数{}", JSON.toJSONString(detail));
                if (null != detail.getSpecialDisamount() && detail.getSpecialDisamount().compareTo(BigDecimal.ZERO) != 0) {
                    if (null == tempOrder.getOldSpecDisamount()) {
                        return sendAjaxError(BASEMessage.PARAM_ERROR, "特批优惠参数非法！");
                    }
                }
            }
        }
        try {
            //返回结果
            int result = this.xeVenOrderService.updateSpecialDisamount(xeVenOrderForm.getXeVenOrderForm(), userInfo, getRequestIP());
            Map<String, Object> resultMap = new HashMap<String, Object>();
            if (result == XeConstans._XE_ONE) {
                resultMap.put(XeVenBusConstans.CODE, XeVenBusConstans.BUSSINESS_SUCCESS);
                resultMap.put(XeVenBusConstans.MSG, XeVenOrderMsg.SUCCESS);
            } else {
                resultMap.put(XeVenBusConstans.CODE, XeVenBusConstans.BUSSINESS_ERROR);
                resultMap.put(XeVenBusConstans.MSG, XeVenOrderMsg.SPEC_AMOUNT_FAIL);
            }
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("更新特批优惠金额异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 锁单
     *
     * @author ruancz
     */
    @RequestMapping("lockOrder")
    public @ResponseBody
    BaseResponse lockOrder(@RequestBody XeVenOrderFromVo orderForm) {

        log.info("锁单请求参数为：{}", JSON.toJSONString(orderForm));
        //验证必要参数
        boolean flag = ((null == orderForm) || orderForm.getXeVenOrderForm().size() == XeConstans._XE_ZERO || orderForm.getXeVenOrderForm().size() > XeConstans._XE_TEN);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());

        try {
            //返回结果
            int result = this.xeVenOrderService.updateLockOrderInfo(orderForm.getXeVenOrderForm(), userInfo, XeConstans._XE_STR_ONE);
            if (result == XeConstans._XE_ONE) {
                return sendAjaxOK();
            } else {
                return sendAjaxError();
            }
        } catch (Exception e) {
            log.error("锁单异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 解锁
     *
     * @author ruancz
     */
    @RequestMapping("unLockOrder")
    public @ResponseBody
    BaseResponse unLockOrder(@RequestBody XeVenOrderFromVo orderForm) {

        log.info("解锁订单请求参数为：{}", JSON.toJSONString(orderForm));
        //验证必要参数
        boolean flag = ((null == orderForm) || orderForm.getXeVenOrderForm().size() == XeConstans._XE_ZERO || orderForm.getXeVenOrderForm().size() > XeConstans._XE_TEN);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        //判断是否有由锁单人解锁
        for (int i = 0; i < orderForm.getXeVenOrderForm().size(); i++) {
            orderForm.getXeVenOrderForm().get(i).setLockRemark("无");
            if (!orderForm.getXeVenOrderForm().get(i).getModfiyUser().equals(userInfo.getLoginName()) && userInfo.getAdminFlag() != XeConstans._XE_ONE) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, "请联系锁单人" + orderForm.getXeVenOrderForm().get(i).getModfiyUser() + "/超级管理员进行解锁操作");
            }
        }
        try {
            //返回结果
            int result = this.xeVenOrderService.updateLockOrderInfo(orderForm.getXeVenOrderForm(), userInfo, XeConstans._XE_STR_TWO);
            if (result == XeConstans._XE_ONE) {
                return sendAjaxOK();
            } else {
                return sendAjaxError();
            }
        } catch (Exception e) {
            log.error("解锁订单异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 单条审核订单
     *
     * @author ruancz
     */
    @RequestMapping("auditOrder")
    public @ResponseBody
    BaseResponse auditOrder(@RequestBody XeVenOrderFromVo formList) {

        log.info("单条审核订单请求参数为：{}", JSON.toJSONString(formList));
        //验证请求参数
        boolean flag = ((null == formList) || formList.getXeVenOrderForm().size() == XeConstans._XE_ZERO);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        for (int i = 0; i < formList.getXeVenOrderForm().size(); i++) {
            //判断订单是否锁单
            if (formList.getXeVenOrderForm().get(i).getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
            }
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            this.xeVenOrderService.updateBatchAuditOrder(formList.getXeVenOrderForm(), userInfo, getRequestIP());
            return sendAjaxOK();
        } catch (Exception e) {
            log.error("单条审核订单异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 批量审核订单
     *
     * @author ruancz
     */
    @RequestMapping("batchAuditOrder")
    public @ResponseBody
    BaseResponse batchAuditOrder(@RequestBody XeVenOrderFromVo formList) {

        log.info("批量审核订单请求参数为：{}", JSON.toJSONString(formList));
        //验证请求参数
        boolean flag = ((null == formList) || formList.getXeVenOrderForm().size() == XeConstans._XE_ZERO);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        if (formList.getXeVenOrderForm().size() > 50) {
            return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.MAX_SIZE);
        }
        for (int i = 0; i < formList.getXeVenOrderForm().size(); i++) {
            //判断订单是否锁单
            if (formList.getXeVenOrderForm().get(i).getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
            }
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            this.xeVenOrderService.updateBatchAuditOrder(formList.getXeVenOrderForm(), userInfo, getRequestIP());
            return sendAjaxOK();
        } catch (Exception e) {
            log.error("审核异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 单条取消审核
     *
     * @author ruancz
     */
    @RequestMapping("unAuditOrder")
    public @ResponseBody
    BaseResponse unAuditOrder(@RequestBody XeVenOrderFromVo formList) {

        log.info("取消审核请求参数为：{}", JSON.toJSONString(formList));
        //验证请求参数
        boolean flag = ((null == formList) || formList.getXeVenOrderForm().size() == XeConstans._XE_ZERO || formList.getXeVenOrderForm().size() > XeConstans._XE_TEN);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        for (int i = 0; i < formList.getXeVenOrderForm().size(); i++) {
            //判断订单是否锁单
            if (formList.getXeVenOrderForm().get(i).getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
            }
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.updateUnBatchAuditOrder(formList.getXeVenOrderForm(), userInfo, getRequestIP());
            //取消审核通知前台
            if (resultMap.containsKey("cancelOrderId")) {

            }
            return sendAjaxOK();
        } catch (Exception e) {
            log.error("取消审核异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 批量取消审核
     *
     * @author ruancz
     */
    @RequestMapping("unBatchAuditOrder")
    public @ResponseBody
    BaseResponse unBatchAuditOrder(@RequestBody XeVenOrderFromVo formList) {

        log.info("取消审核请求参数为：{}", JSON.toJSONString(formList));
        //验证请求参数
        boolean flag = ((null == formList) || formList.getXeVenOrderForm().size() == XeConstans._XE_ZERO || formList.getXeVenOrderForm().size() > XeConstans._XE_TEN);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        for (int i = 0; i < formList.getXeVenOrderForm().size(); i++) {
            //判断订单是否锁单
            if (formList.getXeVenOrderForm().get(i).getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
            }
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.updateUnBatchAuditOrder(formList.getXeVenOrderForm(), userInfo, getRequestIP());
            return sendAjaxOK();
        } catch (Exception e) {
            log.error("取消审核异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 废弃订单
     *
     * @author ruancz
     */
    @RequestMapping("cancelOrder")
    public @ResponseBody
    BaseResponse cancelOrder(@RequestBody XeVenOrderFromVo formList) {

        log.info("取消订单请求参数为：{}", JSON.toJSONString(formList));
        //验证请求参数
        boolean flag = ((null == formList) || formList.getXeVenOrderForm().size() == XeConstans._XE_ZERO || formList.getXeVenOrderForm().size() > XeConstans._XE_TEN);
        if (flag) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        for (int i = 0; i < formList.getXeVenOrderForm().size(); i++) {
            //判断订单是否锁单
            if (formList.getXeVenOrderForm().get(i).getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
            }
        }
        try {
            //批量废弃订单
            this.xeVenOrderService.cancelOrder(formList.getXeVenOrderForm(), userInfo, getRequestIP());
            return sendAjaxOK();
        } catch (Exception e) {
            log.error("取消订单异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 批量修改订单实发数量
     *
     * @author ruancz
     */
    @RequestMapping("batchOrderRealSendNum")
    public @ResponseBody
    BaseResponse batchOrderRealSendNum(@RequestBody XeVenOrderFromVo xeVenSplitOrderForm) {

        log.info("修改订单实发数量请求参数为：{}", JSON.toJSONString(xeVenSplitOrderForm));
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        if (null == xeVenSplitOrderForm || xeVenSplitOrderForm.getXeVenSplitOrderForm().size() == XeConstans._XE_ZERO) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        if (xeVenSplitOrderForm.getXeVenSplitOrderForm().size() > 50) {
            return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.MAX_SIZE);
        }
        for (int i = 0; i < xeVenSplitOrderForm.getXeVenSplitOrderForm().size(); i++) {
            //判断订单是否锁单
            if (VenOrderLockEnum.LOCKED.getValue().equals(xeVenSplitOrderForm.getXeVenSplitOrderForm().get(i).getLockStatus())) {
                return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
            }
        }
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.updateOrderRealSendNum(userInfo, xeVenSplitOrderForm.getXeVenSplitOrderForm(), getRequestIP());
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("修改订单实发数量异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 单条修改订单实发数量
     *
     * @author ruancz
     */
    @RequestMapping("updateOrderRealSendNum")
    public @ResponseBody
    BaseResponse updateOrderRealSendNum(@RequestBody XeVenSplitOrderForm xeVenSplitOrderForm) {
        log.info("单条修改订单实发数量：{}", JSON.toJSONString(xeVenSplitOrderForm));
        if (null == xeVenSplitOrderForm || StringUtils.isBlank(xeVenSplitOrderForm.getOrderId())) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        //判断订单是否锁单
        if (xeVenSplitOrderForm.getLockStatus() == VenOrderLockEnum.LOCKED.getValue()) {
            return sendAjaxError(BASEMessage.PARAM_ERROR, XeVenOrderMsg.UNLOCK_MSG);
        }
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.updateOrderSendNum(userInfo, xeVenSplitOrderForm, getRequestIP(), SysCmsPagePlatEnum.PC);
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("单条修改订单实发数量：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 订单汇总采购取消审核
     *
     * @author ruancz
     */
    @RequestMapping("cancelAuditSummaryPurch")
    public @ResponseBody
    BaseResponse cancelAuditSummaryPurch(@RequestBody XeVenOrderFromVo orderFromVo) {
        log.info("单条修改订单实发数量：{}", JSON.toJSONString(orderFromVo));
        if (null == orderFromVo || orderFromVo.getXeVenOrderForm().size() == 0 || orderFromVo.getXeVenOrderForm().size() > XeConstans._XE_TEN) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.cancelAuditSummaryPurch(userInfo, orderFromVo.getXeVenOrderForm(), getRequestIP());
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("单条修改订单实发数量：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询汇总商品
     *
     * @author ruancz
     */
    @RequestMapping("countSummaryPurch")
    public @ResponseBody
    BaseResponse countSummaryPurch(@RequestBody XeVenOrderFromVo orderFromVo) {
        log.info("查询汇总商品：{}", JSON.toJSONString(orderFromVo));
        if (null == orderFromVo || orderFromVo.getXeVenOrderForm().size() == 0 || orderFromVo.getXeVenOrderForm().size() > XeConstans._XE_TEN) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.countSummaryPurch(userInfo, orderFromVo.getXeVenOrderForm());
            resultMap.put("picServer", paramConfig.getImgUrl() + XeConstans.ERP_PRO_PIC_DIR); //图片服务器地址
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询汇总商品：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 插入汇总采购单
     *
     * @author ruancz
     */
    @RequestMapping("insertSummaryPurch")
    public @ResponseBody
    BaseResponse insertSummaryPurch(@RequestBody XeVenOrderFromVo orderFromVo) {
        log.info("插入汇总采购单：{}", JSON.toJSONString(orderFromVo));
        if (null == orderFromVo || orderFromVo.getXeVenSplitOrderForm().size() == 0 || orderFromVo.getXeVenSplitOrderForm().size() > XeConstans._XE_TEN) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.insertSummaryPurch(userInfo, orderFromVo, getRequestIP());
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("插入汇总采购单异常：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 查询业务员列表
     *
     * @author ruancz
     */
    @RequestMapping("querySalesMan")
    public @ResponseBody
    BaseResponse querySalesMan() {
        try {
            List<Map<String, Object>> list = this.xeVenOrderService.querySalesMan();
            Map<String, Object> resultMap = new HashMap<String, Object>();
            resultMap.put("list", list);
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.error("查询业务员列表：{}", e);
            return sendAjaxError();
        }
    }

    /**
     * 订单手动关联采购单
     *
     * @author ruancz
     */
    @RequestMapping("insertOrderRelationPurch")
    public @ResponseBody
    BaseResponse insertOrderRelationPurch(@RequestBody @Valid XeVenOrderFromVo orderFromVo, BindingResult bindingResult) {
        if (null == orderFromVo || orderFromVo.getOrderRelationPurchForm().size() == 0) {
            return sendAjaxError(BASEMessage.PARAM_ERROR);
        }
        if (bindingResult.hasErrors()) {
            return sendAjaxError(BASEMessage.PARAM_ERROR, bindingResult.getFieldError().getDefaultMessage());
        }
        log.info("订单关联采购单：{}", JSON.toJSONString(orderFromVo));
        try {
            Map<String, Object> resultMap = this.xeVenOrderService.insertOrderRelationPurch(orderFromVo.getOrderRelationPurchForm());
            return sendAjaxOK(resultMap);
        } catch (Exception e) {
            log.info("订单关联采购单异常：{}", e);
            return sendAjaxError();
        }
    }

}
  
